package com.jl.jlapp.mvp.activity;

import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.SpannableStringBuilder;
import android.text.TextPaint;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import butterknife.BindView;
import butterknife.ButterKnife;

import com.jl.jlapp.R;
import com.jl.jlapp.eneity.LoginModel;
import com.jl.jlapp.eneity.MessageCodeModel;
import com.jl.jlapp.nets.Api;
import com.jl.jlapp.nets.CommonObserver;
import com.jl.jlapp.nets.Net;
import com.jl.jlapp.utils.Tools;

import io.reactivex.Flowable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

public class BindPhoneActivity
        extends AppCompatActivity {
    String account = "";
    String beforMobile = "";
    @BindView(R.id.connect_server)
    TextView connect_server;
    long failureTime = -1L;
    @BindView(R.id.get_code)
    TextView get_code;
    String inputCode = "";
    @BindView(R.id.login)
    TextView login;
    String messageCode = "";
    String mobile = "";
    @BindView(R.id.password)
    EditText password;
    @BindView(R.id.phone_number)
    EditText phone_number;
    @BindView(R.id.return_btn)
    ImageView returnBtn;
    @BindView(R.id.tips)
    TextView tipsView;
    int type = -1;

    private void init() {
        handleTips();
        this.phone_number.setInputType(3);
        this.password.setInputType(2);
        this.get_code.setOnClickListener(new OnClickListener() {
            public void onClick(View paramAnonymousView) {
                BindPhoneActivity.this.mobile = BindPhoneActivity.this.phone_number.getText().toString().trim();
                BindPhoneActivity.this.beforMobile = BindPhoneActivity.this.mobile;
                if ("".equals(BindPhoneActivity.this.mobile)) {
                    Toast.makeText(BindPhoneActivity.this, "请输入手机号", Toast.LENGTH_SHORT).show();
                    return;
                }
                if (!BindPhoneActivity.this.isMobile(BindPhoneActivity.this.mobile)) {
                    Toast.makeText(BindPhoneActivity.this, "请输入正确的手机号", Toast.LENGTH_SHORT).show();
                    return;
                }
                Net.get().getMessageCode(BindPhoneActivity.this.mobile)
                        .subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
                        .subscribe(new CommonObserver<MessageCodeModel>() {
                            @Override
                            protected void onError(String errorMsg) {

                            }

                            @Override
                            protected void onSuccess(MessageCodeModel messageCodeModel) {

                            }
                        });
            }
        });
        this.login.setOnClickListener(new OnClickListener() {
            public void onClick(View paramAnonymousView) {
                BindPhoneActivity.this.inputCode = BindPhoneActivity.this.password.getText().toString().trim();
                BindPhoneActivity.this.mobile = BindPhoneActivity.this.phone_number.getText().toString().trim();
                long l = System.currentTimeMillis();
                if ("".equals(BindPhoneActivity.this.mobile)) {
                    Toast.makeText(BindPhoneActivity.this, "请输入手机号", Toast.LENGTH_SHORT).show();
                }

                if (!BindPhoneActivity.this.isMobile(BindPhoneActivity.this.mobile)) {
                    Toast.makeText(BindPhoneActivity.this, "请输入正确的手机号", Toast.LENGTH_SHORT).show();
                    return;
                }
                if ("".equals(BindPhoneActivity.this.messageCode)) {
                    Toast.makeText(BindPhoneActivity.this, "请先获取动态密码", Toast.LENGTH_SHORT).show();
                    return;
                }
                if ("".equals(BindPhoneActivity.this.inputCode)) {
                    Toast.makeText(BindPhoneActivity.this, "请输入动态密码", Toast.LENGTH_SHORT).show();
                    return;
                }
                if (BindPhoneActivity.this.failureTime == -1L) {
                    Toast.makeText(BindPhoneActivity.this, "请先获取动态密码", Toast.LENGTH_SHORT).show();
                    return;
                }
                if (l > BindPhoneActivity.this.failureTime) {
                    Toast.makeText(BindPhoneActivity.this, "动态密码已失效，请重新获取", Toast.LENGTH_SHORT).show();
                    return;
                }

                if (!BindPhoneActivity.this.inputCode.equals(BindPhoneActivity.this.messageCode)) {
                    Toast.makeText(BindPhoneActivity.this, "动态密码错误", Toast.LENGTH_SHORT).show();
                }
                if (BindPhoneActivity.this.inputCode.equals(BindPhoneActivity.this.messageCode)) {
                    if (!BindPhoneActivity.this.beforMobile.equals(BindPhoneActivity.this.mobile)) {
                        Toast.makeText(BindPhoneActivity.this, "手机号与动态密码不匹配，请重试", Toast.LENGTH_SHORT).show();
                        return;
                    }
                    Net.get().bindPhone(BindPhoneActivity.this.mobile, BindPhoneActivity.this.account, BindPhoneActivity.this.type).subscribeOn(Schedulers.io())
                            .observeOn(AndroidSchedulers.mainThread()).subscribe(new CommonObserver<LoginModel>() {
                        @Override
                        protected void onError(String errorMsg) {

                        }

                        @Override
                        protected void onSuccess(LoginModel loginModel) {

                        }
                    });
                }


            }
        });
        this.connect_server.setOnClickListener(new OnClickListener() {
            public void onClick(View paramAnonymousView) {
                Toast.makeText(BindPhoneActivity.this, "正在开发中...", Toast.LENGTH_SHORT).show();
            }
        });
        this.returnBtn.setOnClickListener(new OnClickListener() {
            public void onClick(View paramAnonymousView) {
                BindPhoneActivity.this.finish();
            }
        });
    }

    public void handleTips() {
        String str = this.tipsView.getText().toString().trim();
        SpannableStringBuilder localSpannableStringBuilder = new SpannableStringBuilder(str);
        localSpannableStringBuilder.setSpan(new ClickableSpan() {
            public void onClick(View paramAnonymousView) {
                Toast.makeText(BindPhoneActivity.this, "暂无内容!", Toast.LENGTH_LONG).show();
            }

            public void updateDrawState(TextPaint paramAnonymousTextPaint) {
                super.updateDrawState(paramAnonymousTextPaint);
                paramAnonymousTextPaint.setColor(BindPhoneActivity.this.getResources().getColor(R.color.black));
                paramAnonymousTextPaint.setUnderlineText(false);
                paramAnonymousTextPaint.clearShadowLayer();
            }
        }, str.length() - 6, str.length(), 33);
        this.tipsView.setText(localSpannableStringBuilder);
        this.tipsView.setMovementMethod(LinkMovementMethod.getInstance());
    }

    public boolean isMobile(String paramString) {
        if (TextUtils.isEmpty(paramString)) {
            return false;
        }
        return paramString.matches("[1][34578]\\d{9}");
    }

    protected void onCreate(Bundle paramBundle) {
        super.onCreate(paramBundle);
        setContentView(R.layout.activity_bind_phone);
        ButterKnife.bind(this);
        Tools.addActivity(this);
        Intent intent = getIntent();
        this.account = intent.getStringExtra("account");
        this.type = intent.getIntExtra("type", -1);
        Log.d("bindPhone", "onCreate: account:" + this.account);
        init();
    }
}


/* Location:              /Users/davidzhang/Documents/decompileApk/jlfood-dex2jar.jar!/com/jl/jlapp/mvp/activity/BindPhoneActivity.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */